/**
 * 描述: 服务内容详情页
 *
 * @author fengxuecai
 * @since 2021/11/17 14:19
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;
    form.render(null, "zmn-form");

    // 自定义验证规则
    form.verify({
        count: function (value) {
            if (value.length > 50) {
                return "服务内容不能大于50个字符";
            }
        },
        sort: function (value) {
            if (value && !/^[0-9]+$/.test(value)) {
                return "排序值只能是正整数";
            }
            if (value.length > 10) {
                return "排序值不能大于10位正整数";
            }
        }
    });

    // 提交
    form.on('submit(zmn-form-submit)', function (obj) {
        var data = obj.field;
        var url = "/base/servicecontent/addEdit.action";
        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success: function (result) {
                if (result.status == 200) {
                    layer.msg(result.message, {"time": 1000}, function () {
                        parent.location.reload();
                    });
                } else {
                    layer.msg(result.message, {"icon": 2});
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        })
        return false;
    });
    //对外暴露的接口
    exports('plat_base_servicecontent_detail', {});
});
